package com.nf.health.app.inquiry.impl.viewholder;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.nf.health.app.Constants;
import com.nf.health.app.R;
import com.nf.health.app.activity.hostopal.BookingRegisteredActivity;
import com.nf.health.app.inquiry.bean.DoctorDetailBean;
import com.nf.health.app.inquiry.docdetail.DocHomeOrderActivity;
import com.nf.health.app.inquiry.docdetail.DocPayConunselActivity;
import com.nf.health.app.models.DoctorHome;
import com.nf.health.app.models.DoctorServiceSettingModel;
import com.nf.health.app.utils.ActivityUtils;
import com.nf.health.app.utils.GetToast;
import com.nf.health.app.utils.ViewUtil;

import java.util.List;

/**
 * Created by Jason on 2016/9/21.
 * 家庭服务，付费咨询，健康管理
 */
public class DoctorFunctionViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
//    @Bind(R.id.tv_money_ask_doc)
//    TextView tv_money_ask_doc;//家庭服务的起送价格

//    @Bind(R.id.tv_pay_direct_txt)//付费咨询的起送价格
//            TextView tv_pay_direct_txt;

//    @Bind(R.id.ll_house_service)//家庭服务
            LinearLayout ll_house_service;
//    @Bind(R.id.rl_house_service)
            RelativeLayout rl_house_service;


//    @Bind(R.id.rl_pay_money_direc)//付费咨询
            RelativeLayout rl_pay_money_direc;

//    @Bind(R.id.rl_health_manager)//健康管理
            RelativeLayout rl_health_manager;


//    @Bind(R.id.rl_yygh)//预约挂号
            RelativeLayout rl_yygh;

//    @Bind(R.id.iv_home_service)
    ImageView iv_home_service;


//    @Bind(R.id.iv_paymoney_descript)
    ImageView iv_paymoney_descript;

//    @Bind(R.id.tv_health_dmanager)
    ImageView tv_health_dmanager;

   /* @Bind(R.id.tv_health_pay)
    TextView tv_health_pay;*/

//    @Bind(R.id.iv_doc_yygh)
    ImageView iv_doc_yygh;

    DoctorServiceSettingModel familyDoctorServiceSetting = null;
    DoctorServiceSettingModel peyMoneyDescriptDoctorServiceSetting = null;
    DoctorServiceSettingModel HeanthymanagerDoctorServiceSetting =  null;
    private String doctorId = "";
    private Activity cnt;
    private String REGISTRATIONSTATE;
    public DoctorFunctionViewHolder(View itemView, Activity cnt) {
        super(itemView);
//        ButterKnife.bind(this, itemView);
        this.cnt = cnt;
        ll_house_service = ViewUtil.getView(itemView,R.id.ll_house_service);

        rl_house_service = ViewUtil.getView(itemView,R.id.rl_house_service);
        rl_pay_money_direc = ViewUtil.getView(itemView,R.id.rl_pay_money_direc);
        rl_health_manager = ViewUtil.getView(itemView,R.id.rl_health_manager);
        rl_yygh = ViewUtil.getView(itemView,R.id.rl_yygh);
        iv_home_service = ViewUtil.getView(itemView,R.id.iv_home_service);
        iv_paymoney_descript = ViewUtil.getView(itemView,R.id.iv_paymoney_descript);
        tv_health_dmanager = ViewUtil.getView(itemView,R.id.tv_health_dmanager);
        iv_doc_yygh = ViewUtil.getView(itemView,R.id.iv_doc_yygh);

        ll_house_service.setOnClickListener(this);
        rl_house_service.setOnClickListener(this);
        rl_health_manager.setOnClickListener(this);
        rl_pay_money_direc.setOnClickListener(this);
        rl_house_service.setOnClickListener(this);
        rl_yygh.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case  R.id.rl_health_manager://健康管理
                //ActivityUtils.showActivity(cnt, BanklPlaceDoctorListActivity.class);
                GetToast.useString(cnt, "暂未开通");
                break;
            case  R.id.ll_house_service://家庭服务
            case  R.id.rl_house_service:
                if(familyDoctorServiceSetting == null){
                    return ;
                }
                if(familyDoctorServiceSetting.getIsopen() == 0 && familyDoctorServiceSetting.getIsopen() == -1){//功能不存在
                    GetToast.useString(cnt, "功能不存在！");
                    return ;
                }else if(familyDoctorServiceSetting.getIsopen() == 1){//0未开启
                    GetToast.useString(cnt, "功能未开启");
                    return ;
                }else if(familyDoctorServiceSetting.getIsopen() == 2){//1已开启
                    if(TextUtils.isEmpty(doctorId)){
                        GetToast.useString(cnt, "缺少参数!");
                        return ;
                    }
                }
                Bundle docDetailBundle2 = new Bundle();
                docDetailBundle2.putString(Constants.DOCTOR_ID, doctorId);
                ActivityUtils.showActivity(cnt, DocHomeOrderActivity.class, docDetailBundle2);
                break;
            case  R.id.rl_pay_money_direc://付费咨询
                // isopen	-1功能不存在，0未开启，1已开启
                if(peyMoneyDescriptDoctorServiceSetting == null){
                    return ;
                }
                if(peyMoneyDescriptDoctorServiceSetting.getIsopen() == 0 || peyMoneyDescriptDoctorServiceSetting.getIsopen() == -1){//功能不存在
                    GetToast.useString(cnt, "功能不存在！");
                    return ;
                }else if(peyMoneyDescriptDoctorServiceSetting.getIsopen() == 1){//0未开启
                    GetToast.useString(cnt, "功能未开启");
                    return ;
                }else if(peyMoneyDescriptDoctorServiceSetting.getIsopen() == 2){//1已开启
                    if(TextUtils.isEmpty(doctorId)){
                        GetToast.useString(cnt, "缺少参数!");
                        return ;
                    }
                }
                Bundle docDetailBundle = new Bundle();
                docDetailBundle.putString(Constants.DOCTOR_ID, doctorId);
                ActivityUtils.showActivity(cnt, DocPayConunselActivity.class, docDetailBundle);
                break;
            case R.id.rl_yygh:
                Bundle docDetailBundle4 = new Bundle();
                docDetailBundle4.putString(BookingRegisteredActivity.DOCOTORID, doctorId);
                docDetailBundle4.putString(BookingRegisteredActivity.HID, bean.getHid());
                ActivityUtils.showActivity(cnt, BookingRegisteredActivity.class, docDetailBundle4);
                break;
        }
    }

    public void loadData(DoctorHome doctorDetail){
        if(doctorDetail == null){
            return ;
        }
    }
    DoctorDetailBean bean;
    public void loadData(DoctorDetailBean bean){
        this.bean = bean;
    }

    /**
     * 刷新布局
     */
    public void   reFreshMyTvText(List<DoctorServiceSettingModel> doctorServiceSettingModelList){
       /* if(!NetUtil.isNetworkAvailable(cnt)){
            tv_money_ask_doc.setText("");
            tv_pay_direct_txt.setText("");
        }*/
        if(doctorServiceSettingModelList == null){
            return ;
        }
        familyDoctorServiceSetting = doctorServiceSettingModelList.get(0);
        peyMoneyDescriptDoctorServiceSetting = doctorServiceSettingModelList.get(1);
        HeanthymanagerDoctorServiceSetting = doctorServiceSettingModelList.get(2);
        doctorId = familyDoctorServiceSetting.getDoctorId();

        //家庭服务

        if(familyDoctorServiceSetting.getIsopen() == 1 ){//-1功能不存在，1未开启，2已开启
            iv_home_service.setImageResource(R.drawable.ic_doc_hourse_gray);
          //  tv_money_ask_doc.setText("功能未开启");
        }else if(familyDoctorServiceSetting.getIsopen() == 2 ){
            iv_home_service.setImageResource(R.drawable.ic_doc_hourse);
            try{
             //   tv_money_ask_doc.setText("¥"+(TextUtils.isEmpty(familyDoctorServiceSetting.getLowest()) ? "0.00" : Util.saveDecimalTwo(Double.parseDouble(familyDoctorServiceSetting.getLowest())))+ " 元起");
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        if(peyMoneyDescriptDoctorServiceSetting.getIsopen() == 1 ){//-1功能不存在，1未开启，2已开启
            iv_paymoney_descript.setImageResource(R.drawable.ic_doc_ask_gray);
          //  tv_pay_direct_txt.setText("功能未开启");
        }else if(peyMoneyDescriptDoctorServiceSetting.getIsopen() == 2){
            iv_paymoney_descript.setImageResource(R.drawable.ic_doc_ask);
            try{
            //    tv_pay_direct_txt.setText("¥"+(TextUtils.isEmpty(peyMoneyDescriptDoctorServiceSetting.getLowest()) ? "0.00" :Util.saveDecimalTwo(Double.parseDouble(peyMoneyDescriptDoctorServiceSetting.getLowest())))+ " 元起");
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        if(HeanthymanagerDoctorServiceSetting.getIsopen() == 1 ){//-1功能不存在，1未开启，2已开启
          //  tv_health_pay.setText("敬请期待");
            tv_health_dmanager.setImageResource(R.drawable.ic_doc_health_manager_gray);
        }else if( HeanthymanagerDoctorServiceSetting.getIsopen() == 2) {
            tv_health_dmanager.setImageResource(R.drawable.ic_doc_health_manager);
        }
    }

    public void refreshMyGhaoTx(String REGISTRATIONSTATE){
        if(!TextUtils.isEmpty(REGISTRATIONSTATE)){
            if(REGISTRATIONSTATE.equals("2")){//不预约
                iv_doc_yygh.setImageResource(R.drawable.iv_doc_yygh_no);
                rl_yygh.setEnabled(false);
            }else if(REGISTRATIONSTATE.equals("1")){//可预约
                iv_doc_yygh.setImageResource(R.drawable.iv_doc_yygh_has);
                rl_yygh.setEnabled(true);
            }else{
                iv_doc_yygh.setImageResource(R.drawable.iv_doc_yygh_no);
                rl_yygh.setEnabled(false);
            }
        }
    }
}
